package com.spring.gop.proj.service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.spring.gop.proj.interfaces.FaqDao;
import com.spring.gop.proj.interfaces.FaqService;
import com.spring.gop.proj.model.Faq;

@Service
public class FaqServiceImpl implements FaqService{
	@Autowired FaqDao faqDao;
	
	public List<Faq> selectFaqt() {
		return faqDao.selectFaqt();
	}
	public List<Faq> selectFaqu() {
		return faqDao.selectFaqu();
	}
	public List<Faq> selectFaqp() {
		return faqDao.selectFaqp();
	}
	public List<Faq> selectFaqc() {
		return faqDao.selectFaqc();
	}
	public List<Faq> selectFaqe() {
		return faqDao.selectFaqe();
	}
	public List<Faq> selectFaqs() {
		return faqDao.selectFaqs();
	}
	public Faq selectFaq(int num) {
		Faq faq = faqDao.selectFaq(num);
		String contentTxt = faq.getContent().replaceAll("/r/n", "<br/>");
		faq.setContent(contentTxt);
		return faq;
	}
	
	@Transactional
	public void insertFaq(Faq faq) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		faq.setRegdate(sdf.format(cal.getTime()));
		faqDao.insertFaq(faq);
	}
	
	@Transactional
	public void readcount(int num) {
		faqDao.readcount(num);
	}
	
	@Transactional
	public void updateFaq(Faq faq){
		faqDao.updateFaq(faq);
	}
	
	@Transactional
	public void delFaq(int num){
		faqDao.delFaq(num);
	}
}
